package archimede;

import java.awt.Color;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.RenderingHints;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.io.IOException;
import java.net.MalformedURLException;
import java.util.Calendar;
import java.util.Scanner;

import javax.swing.BorderFactory;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JComponent;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;
import javax.swing.UIManager;

import net.miginfocom.swing.MigLayout;

import com.itextpdf.text.BadElementException;
import com.itextpdf.text.BaseColor;
import com.itextpdf.text.Chunk;
import com.itextpdf.text.Document;
import com.itextpdf.text.DocumentException;
import com.itextpdf.text.Element;
import com.itextpdf.text.FontFactory;
import com.itextpdf.text.Image;
import com.itextpdf.text.Paragraph;

public class DatiEdificio extends JPanel {
	// valori tipo edificio
	private String[] elTipoEdificio = { "", "Casa unifamiliare", "Casa bi-famigliare", "Casa Pluri-familiare", "Condominio", "Villa storica",
			"Baita", "Chiesa", "Scuola", "altro" };
	// tipo edificio
	private JComboBox tipoEdificio = new JComboBox(elTipoEdificio);
	// se scelto altro
	private boolean modifyTipoEdificio = false;
	// campo libero tipo edificio
	private JTextField tipoEdificioAltro = new JTextField() {
		@Override
		protected void paintComponent(Graphics g) {
			if (!isOpaque()) {
				int w = getWidth();
				int h = getHeight();
				Graphics2D g2 = (Graphics2D) g.create();
				g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
				g2.setColor(UIManager.getColor("TextField.background"));
				g2.fillRoundRect(0, 0, w - 2, h - 2, 10, 10);
				g2.setColor(Color.BLACK);
				g2.drawRoundRect(0, 0, w - 2, h - 2, 10, 10);
				g2.dispose();
			}
			super.paintComponent(g);
		}
	};

	private JTextField intestatario = new JTextField() {
		@Override
		protected void paintComponent(Graphics g) {
			if (!isOpaque()) {
				int w = getWidth();
				int h = getHeight();
				Graphics2D g2 = (Graphics2D) g.create();
				g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
				g2.setColor(UIManager.getColor("TextField.background"));
				g2.fillRoundRect(0, 0, w - 2, h - 2, 10, 10);
				g2.setColor(Color.BLACK);
				g2.drawRoundRect(0, 0, w - 2, h - 2, 10, 10);
				g2.dispose();
			}
			super.paintComponent(g);
		}
	};
	private JTextField via = new JTextField() {
		@Override
		protected void paintComponent(Graphics g) {
			if (!isOpaque()) {
				int w = getWidth();
				int h = getHeight();
				Graphics2D g2 = (Graphics2D) g.create();
				g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
				g2.setColor(UIManager.getColor("TextField.background"));
				g2.fillRoundRect(0, 0, w - 2, h - 2, 10, 10);
				g2.setColor(Color.BLACK);
				g2.drawRoundRect(0, 0, w - 2, h - 2, 10, 10);
				g2.dispose();
			}
			super.paintComponent(g);
		}
	};
	private JTextField nCivico = new JTextField() {
		@Override
		protected void paintComponent(Graphics g) {
			if (!isOpaque()) {
				int w = getWidth();
				int h = getHeight();
				Graphics2D g2 = (Graphics2D) g.create();
				g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
				g2.setColor(UIManager.getColor("TextField.background"));
				g2.fillRoundRect(0, 0, w - 2, h - 2, 10, 10);
				g2.setColor(Color.BLACK);
				g2.drawRoundRect(0, 0, w - 2, h - 2, 10, 10);
				g2.dispose();
			}
			super.paintComponent(g);
		}
	};
	private JTextField citta = new JTextField() {
		@Override
		protected void paintComponent(Graphics g) {
			if (!isOpaque()) {
				int w = getWidth();
				int h = getHeight();
				Graphics2D g2 = (Graphics2D) g.create();
				g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
				g2.setColor(UIManager.getColor("TextField.background"));
				g2.fillRoundRect(0, 0, w - 2, h - 2, 10, 10);
				g2.setColor(Color.BLACK);
				g2.drawRoundRect(0, 0, w - 2, h - 2, 10, 10);
				g2.dispose();
			}
			super.paintComponent(g);
		}
	};
	private JTextField cap = new JTextField() {
		@Override
		protected void paintComponent(Graphics g) {
			if (!isOpaque()) {
				int w = getWidth();
				int h = getHeight();
				Graphics2D g2 = (Graphics2D) g.create();
				g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
				g2.setColor(UIManager.getColor("TextField.background"));
				g2.fillRoundRect(0, 0, w - 2, h - 2, 10, 10);
				g2.setColor(Color.BLACK);
				g2.drawRoundRect(0, 0, w - 2, h - 2, 10, 10);
				g2.dispose();
			}
			super.paintComponent(g);
		}
	};
	private JTextField provincia = new JTextField() {
		@Override
		protected void paintComponent(Graphics g) {
			if (!isOpaque()) {
				int w = getWidth();
				int h = getHeight();
				Graphics2D g2 = (Graphics2D) g.create();
				g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
				g2.setColor(UIManager.getColor("TextField.background"));
				g2.fillRoundRect(0, 0, w - 2, h - 2, 10, 10);
				g2.setColor(Color.BLACK);
				g2.drawRoundRect(0, 0, w - 2, h - 2, 10, 10);
				g2.dispose();
			}
			super.paintComponent(g);
		}
	};
	private JTextField giorno = new JTextField() {
		@Override
		protected void paintComponent(Graphics g) {
			if (!isOpaque()) {
				int w = getWidth();
				int h = getHeight();
				Graphics2D g2 = (Graphics2D) g.create();
				g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
				g2.setColor(UIManager.getColor("TextField.background"));
				g2.fillRoundRect(0, 0, w - 2, h - 2, 10, 10);
				g2.setColor(Color.BLACK);
				g2.drawRoundRect(0, 0, w - 2, h - 2, 10, 10);
				g2.dispose();
			}
			super.paintComponent(g);
		}
	};
	private JTextField mese = new JTextField() {
		@Override
		protected void paintComponent(Graphics g) {
			if (!isOpaque()) {
				int w = getWidth();
				int h = getHeight();
				Graphics2D g2 = (Graphics2D) g.create();
				g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
				g2.setColor(UIManager.getColor("TextField.background"));
				g2.fillRoundRect(0, 0, w - 2, h - 2, 10, 10);
				g2.setColor(Color.BLACK);
				g2.drawRoundRect(0, 0, w - 2, h - 2, 10, 10);
				g2.dispose();
			}
			super.paintComponent(g);
		}
	};
	private JTextField anno = new JTextField() {
		@Override
		protected void paintComponent(Graphics g) {
			if (!isOpaque()) {
				int w = getWidth();
				int h = getHeight();
				Graphics2D g2 = (Graphics2D) g.create();
				g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
				g2.setColor(UIManager.getColor("TextField.background"));
				g2.fillRoundRect(0, 0, w - 2, h - 2, 10, 10);
				g2.setColor(Color.BLACK);
				g2.drawRoundRect(0, 0, w - 2, h - 2, 10, 10);
				g2.dispose();
			}
			super.paintComponent(g);
		}
	};
	private JTextField tecnico = new JTextField() {
		@Override
		protected void paintComponent(Graphics g) {
			if (!isOpaque()) {
				int w = getWidth();
				int h = getHeight();
				Graphics2D g2 = (Graphics2D) g.create();
				g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
				g2.setColor(UIManager.getColor("TextField.background"));
				g2.fillRoundRect(0, 0, w - 2, h - 2, 10, 10);
				g2.setColor(Color.BLACK);
				g2.drawRoundRect(0, 0, w - 2, h - 2, 10, 10);
				g2.dispose();
			}
			super.paintComponent(g);
		}
	};

	private JTextField committenteIntestatario = new JTextField() {
		@Override
		protected void paintComponent(Graphics g) {
			if (!isOpaque()) {
				int w = getWidth();
				int h = getHeight();
				Graphics2D g2 = (Graphics2D) g.create();
				g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
				g2.setColor(UIManager.getColor("TextField.background"));
				g2.fillRoundRect(0, 0, w - 2, h - 2, 10, 10);
				g2.setColor(Color.BLACK);
				g2.drawRoundRect(0, 0, w - 2, h - 2, 10, 10);
				g2.dispose();
			}
			super.paintComponent(g);
		}
	};
	private JTextField committenteVia = new JTextField() {
		@Override
		protected void paintComponent(Graphics g) {
			if (!isOpaque()) {
				int w = getWidth();
				int h = getHeight();
				Graphics2D g2 = (Graphics2D) g.create();
				g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
				g2.setColor(UIManager.getColor("TextField.background"));
				g2.fillRoundRect(0, 0, w - 2, h - 2, 10, 10);
				g2.setColor(Color.BLACK);
				g2.drawRoundRect(0, 0, w - 2, h - 2, 10, 10);
				g2.dispose();
			}
			super.paintComponent(g);
		}
	};
	private JTextField committenteCivico = new JTextField() {
		@Override
		protected void paintComponent(Graphics g) {
			if (!isOpaque()) {
				int w = getWidth();
				int h = getHeight();
				Graphics2D g2 = (Graphics2D) g.create();
				g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
				g2.setColor(UIManager.getColor("TextField.background"));
				g2.fillRoundRect(0, 0, w - 2, h - 2, 10, 10);
				g2.setColor(Color.BLACK);
				g2.drawRoundRect(0, 0, w - 2, h - 2, 10, 10);
				g2.dispose();
			}
			super.paintComponent(g);
		}
	};
	private JTextField committenteCitta = new JTextField() {
		@Override
		protected void paintComponent(Graphics g) {
			if (!isOpaque()) {
				int w = getWidth();
				int h = getHeight();
				Graphics2D g2 = (Graphics2D) g.create();
				g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
				g2.setColor(UIManager.getColor("TextField.background"));
				g2.fillRoundRect(0, 0, w - 2, h - 2, 10, 10);
				g2.setColor(Color.BLACK);
				g2.drawRoundRect(0, 0, w - 2, h - 2, 10, 10);
				g2.dispose();
			}
			super.paintComponent(g);
		}
	};
	private JTextField committenteCap = new JTextField() {
		@Override
		protected void paintComponent(Graphics g) {
			if (!isOpaque()) {
				int w = getWidth();
				int h = getHeight();
				Graphics2D g2 = (Graphics2D) g.create();
				g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
				g2.setColor(UIManager.getColor("TextField.background"));
				g2.fillRoundRect(0, 0, w - 2, h - 2, 10, 10);
				g2.setColor(Color.BLACK);
				g2.drawRoundRect(0, 0, w - 2, h - 2, 10, 10);
				g2.dispose();
			}
			super.paintComponent(g);
		}
	};
	private JTextField committenteProvincia = new JTextField() {
		@Override
		protected void paintComponent(Graphics g) {
			if (!isOpaque()) {
				int w = getWidth();
				int h = getHeight();
				Graphics2D g2 = (Graphics2D) g.create();
				g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
				g2.setColor(UIManager.getColor("TextField.background"));
				g2.fillRoundRect(0, 0, w - 2, h - 2, 10, 10);
				g2.setColor(Color.BLACK);
				g2.drawRoundRect(0, 0, w - 2, h - 2, 10, 10);
				g2.dispose();
			}
			super.paintComponent(g);
		}
	};
	private JTextField mail = new JTextField() {
		@Override
		protected void paintComponent(Graphics g) {
			if (!isOpaque()) {
				int w = getWidth();
				int h = getHeight();
				Graphics2D g2 = (Graphics2D) g.create();
				g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
				g2.setColor(UIManager.getColor("TextField.background"));
				g2.fillRoundRect(0, 0, w - 2, h - 2, 10, 10);
				g2.setColor(Color.BLACK);
				g2.drawRoundRect(0, 0, w - 2, h - 2, 10, 10);
				g2.dispose();
			}
			super.paintComponent(g);
		}
	};
	private JTextField cell = new JTextField() {
		@Override
		protected void paintComponent(Graphics g) {
			if (!isOpaque()) {
				int w = getWidth();
				int h = getHeight();
				Graphics2D g2 = (Graphics2D) g.create();
				g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
				g2.setColor(UIManager.getColor("TextField.background"));
				g2.fillRoundRect(0, 0, w - 2, h - 2, 10, 10);
				g2.setColor(Color.BLACK);
				g2.drawRoundRect(0, 0, w - 2, h - 2, 10, 10);
				g2.dispose();
			}
			super.paintComponent(g);
		}
	};
	private JTextField tel = new JTextField() {
		@Override
		protected void paintComponent(Graphics g) {
			if (!isOpaque()) {
				int w = getWidth();
				int h = getHeight();
				Graphics2D g2 = (Graphics2D) g.create();
				g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
				g2.setColor(UIManager.getColor("TextField.background"));
				g2.fillRoundRect(0, 0, w - 2, h - 2, 10, 10);
				g2.setColor(Color.BLACK);
				g2.drawRoundRect(0, 0, w - 2, h - 2, 10, 10);
				g2.dispose();
			}
			super.paintComponent(g);
		}
	};

	private StartingWindow st;

	private ProfessionistaPanel professionista;
	
	private JPanel row12 = new JPanel();

	protected void paintComponent(Graphics g) {
		setOpaque(false);
		g.drawImage((new ImageIcon(ClassLoader.getSystemResource("sfondo.jpg"))).getImage(), 0, 0, null);
		super.paintComponent(g);
	}

	public DatiEdificio(StartingWindow sta) {
		super();
		setOpaque(false);
		this.st = sta;
		professionista = new ProfessionistaPanel(st);
		setLayout(new MigLayout("", "", "25[]3[]3[]3[]3[]"));

		JLabel title = new JLabel("Dati edificio :");
		title.setFont(new Font("Arial", Font.BOLD, 20));

		JLabel tipoEdificioLabel = new JLabel("Tipologia edificio :");
		setCell(tipoEdificioLabel);
		tipoEdificio.setPreferredSize(new Dimension(350, 30));
		tipoEdificioAltro.setPreferredSize(new Dimension(350, 30));

		JLabel intestatarioLabel = new JLabel("Intestatario edificio :");
		setCell(intestatarioLabel);
		intestatario.setPreferredSize(new Dimension(350, 30));

		JLabel viaLabel = new JLabel("Via :");
		setCell(viaLabel);
		via.setPreferredSize(new Dimension(417, 30));
		JLabel civicoLabel = new JLabel("Civico :");
		setCell(civicoLabel);
		nCivico.setPreferredSize(new Dimension(70, 30));

		JLabel cittaLabel = new JLabel("Citta' :");
		setCell(cittaLabel);
		citta.setPreferredSize(new Dimension(250, 30));

		JLabel capLabel = new JLabel("C.A.P. :");
		setCell(capLabel);
		cap.setPreferredSize(new Dimension(100, 30));

		JLabel dataAnalisiLabel = new JLabel("Data analisi diagnostica :");
		setCell(dataAnalisiLabel);

		JLabel tecnicoLabel = new JLabel("Tecnico esecutore delle misurazioni :");
		setCell(tecnicoLabel);

		Calendar cal = Calendar.getInstance();
		giorno.setText("" + cal.get(Calendar.DATE));
		mese.setText("" + (cal.get(Calendar.MONTH) + 1));
		anno.setText("" + cal.get(Calendar.YEAR));
		setCell();

		JLabel committente = new JLabel("Committente :");
		committente.setFont(new Font("Arial", Font.BOLD, 20));

		JLabel nomeCommittente = new JLabel("Nome e cognome :");
		setCell(nomeCommittente);
		committenteIntestatario.setPreferredSize(new Dimension(350, 30));

		JLabel viaC = new JLabel("Via :");
		setCell(viaC);
		committenteVia.setPreferredSize(new Dimension(417, 30));

		JLabel civicoC = new JLabel("Civico :");
		setCell(civicoC);
		committenteCivico.setPreferredSize(new Dimension(70, 30));

		JLabel cittaC = new JLabel("Citta' :");
		setCell(cittaC);
		committenteCitta.setPreferredSize(new Dimension(250, 30));

		JLabel capC = new JLabel("C.A.P. :");
		setCell(capC);
		committenteCap.setPreferredSize(new Dimension(100, 30));

		JLabel cellC = new JLabel("Cell. :");
		setCell(cellC);
		cell.setPreferredSize(new Dimension(350, 30));

		JLabel telef = new JLabel("Tel. :");
		setCell(telef);
		tel.setPreferredSize(new Dimension(350, 30));

		JLabel mailC = new JLabel("E-Mail :");
		setCell(mailC);
		mail.setPreferredSize(new Dimension(350, 30));

		JButton repeat = new JButton("Ripeti valori");
		repeat.addActionListener(new ActionListener() {

			@Override
			public void actionPerformed(ActionEvent e) {
				// TODO Auto-generated method stub
				committenteIntestatario.setText(intestatario.getText());
				committenteCap.setText(cap.getText());
				committenteCitta.setText(citta.getText());
				committenteCivico.setText(nCivico.getText());
				committenteVia.setText(via.getText());
				committenteProvincia.setText(provincia.getText());
				paintAll(getGraphics());
			}
		});

		// divido in pannelli
		
		row12.setLayout(new MigLayout());
		row12.setOpaque(false);
		row12.add(tipoEdificioLabel, "cell 0 0 3 1");
		row12.add(tipoEdificio, "cell 0 0 3 1");

		row12.add(intestatarioLabel, "cell 0 2 3 1");
		row12.add(intestatario, "cell 0 2 5 1");

		tipoEdificio.addActionListener(new ActionListener() {

			@Override
			public void actionPerformed(ActionEvent e) {
				if (((String) tipoEdificio.getSelectedItem()).equalsIgnoreCase("altro")) {
					row12.remove(tipoEdificio);
					row12.add(tipoEdificioAltro, "cell 0 0 3 1");
					modifyTipoEdificio = true;
					paintAll(getGraphics());
				}
			}
		});
		MouseAdapter ml = new MouseAdapter() {
			public void mousePressed(MouseEvent e) {
				if (e.getButton() == MouseEvent.BUTTON3) {
					row12.remove(tipoEdificioAltro);
					tipoEdificio.setSelectedIndex(0);
					row12.add(tipoEdificio, "cell 0 0 3 1");
					modifyTipoEdificio = false;
					paintAll(getGraphics());
				}
			}
		};
		tipoEdificioAltro.addMouseListener(ml);

		JPanel row345 = new JPanel();
		row345.setLayout(new MigLayout());
		row345.setOpaque(false);
		row345.add(viaLabel, "cell 0 0");
		row345.add(via, "cell 1 0 3 1");
		row345.add(civicoLabel, "cell 4 0");
		row345.add(nCivico, "cell 5 0");
		row345.add(cittaLabel, "cell 0 1");
		row345.add(citta, "cell 1 1");
		row345.add(capLabel, "cell 2 1");
		row345.add(cap, "cell 3 1");
		row345.add(new JLabel("Provincia") {
			@Override
			public void setFont(Font font) {
				// TODO Auto-generated method stub
				super.setFont(new Font("Arial", Font.BOLD, 16));
			}
		}, "cell 4 1");
		row345.add(provincia, "cell 5 1");

		JPanel row67 = new JPanel();
		row67.setLayout(new MigLayout());
		row67.setOpaque(false);
		row67.add(dataAnalisiLabel);
		row67.add(giorno);

		row67.add(mese);

		row67.add(anno, "wrap");

		row67.add(tecnicoLabel, "span 3");
		row67.add(tecnico);

		add(title, "wrap , gapleft 20");
		add(row12, "wrap, gapleft 15");
		add(row345, "wrap, gapleft 15");
		add(row67, "wrap, gapleft 15");

		JPanel cmtt = new JPanel();
		cmtt.setLayout(new MigLayout());
		cmtt.setOpaque(false);
		cmtt.add(committente);
		cmtt.add(repeat);

		JPanel Crow12 = new JPanel();
		Crow12.setLayout(new MigLayout());
		Crow12.setOpaque(false);
		Crow12.add(nomeCommittente, "cell 0 0 2 1");
		Crow12.add(committenteIntestatario, "cell 2 0 6 1");

		JPanel Crow345 = new JPanel();
		Crow345.setLayout(new MigLayout());
		Crow345.setOpaque(false);
		Crow345.add(viaC, "cell 0 0");
		Crow345.add(committenteVia, "cell 1 0 3 1");
		Crow345.add(civicoC, "cell 4 0");
		Crow345.add(committenteCivico, "cell 5 0");
		Crow345.add(cittaC, "cell 0 1");
		Crow345.add(committenteCitta, "cell 1 1");
		Crow345.add(capC, "cell 2 1");
		Crow345.add(committenteCap, "cell 3 1");
		Crow345.add(new JLabel("Provincia") {
			@Override
			public void setFont(Font font) {
				// TODO Auto-generated method stub
				super.setFont(new Font("Arial", Font.BOLD, 16));
			}
		}, "cell 4 1");
		Crow345.add(committenteProvincia, "cell 5 1");

		JPanel Crow67 = new JPanel();
		Crow67.setLayout(new MigLayout());
		Crow67.setOpaque(false);
		Crow67.add(mailC, "cell 0 0");
		Crow67.add(mail, "cell 1 0");
		Crow67.add(cellC, "cell 0 1");
		Crow67.add(cell, "cell 1 1");
		Crow67.add(telef, "cell 0 2");
		Crow67.add(tel, "cell 1 2");

		add(cmtt, "wrap , gapleft 15");
		add(Crow12, "wrap, gapleft 15");
		add(Crow345, "wrap, gapleft 15");
		add(Crow67, "wrap, gapleft 15");

		add(professionista, "gapleft 15");

	}

	public void setCell(JComponent c) {
		c.setFont(new Font("Arial", Font.BOLD, 16));
	}

	public void setCell() {
		tipoEdificioAltro.setBorder((BorderFactory.createEmptyBorder(4, 8, 4, 8)));
		intestatario.setBorder((BorderFactory.createEmptyBorder(4, 8, 4, 8)));
		via.setBorder((BorderFactory.createEmptyBorder(4, 8, 4, 8)));
		citta.setBorder((BorderFactory.createEmptyBorder(4, 8, 4, 8)));
		nCivico.setBorder((BorderFactory.createEmptyBorder(4, 8, 4, 8)));
		giorno.setBorder((BorderFactory.createEmptyBorder(4, 8, 4, 8)));
		mese.setBorder((BorderFactory.createEmptyBorder(4, 8, 4, 8)));
		anno.setBorder((BorderFactory.createEmptyBorder(4, 8, 4, 8)));
		tecnico.setBorder((BorderFactory.createEmptyBorder(4, 8, 4, 8)));
		cap.setBorder((BorderFactory.createEmptyBorder(4, 8, 4, 8)));
		committenteCap.setBorder((BorderFactory.createEmptyBorder(4, 8, 4, 8)));
		committenteCitta.setBorder((BorderFactory.createEmptyBorder(4, 8, 4, 8)));
		committenteCivico.setBorder((BorderFactory.createEmptyBorder(4, 8, 4, 8)));
		committenteIntestatario.setBorder((BorderFactory.createEmptyBorder(4, 8, 4, 8)));
		committenteVia.setBorder((BorderFactory.createEmptyBorder(4, 8, 4, 8)));
		mail.setBorder((BorderFactory.createEmptyBorder(4, 8, 4, 8)));
		cell.setBorder((BorderFactory.createEmptyBorder(4, 8, 4, 8)));
		tel.setBorder((BorderFactory.createEmptyBorder(4, 8, 4, 8)));
		provincia.setBorder((BorderFactory.createEmptyBorder(4, 8, 4, 8)));
		committenteProvincia.setBorder((BorderFactory.createEmptyBorder(4, 8, 4, 8)));

		tipoEdificio.setFont(new Font("Arial", Font.PLAIN, 16));
		tipoEdificioAltro.setFont(new Font("Arial", Font.PLAIN, 16));
		intestatario.setFont(new Font("Arial", Font.PLAIN, 16));
		nCivico.setFont(new Font("Arial", Font.PLAIN, 16));
		cap.setFont(new Font("Arial", Font.PLAIN, 16));
		via.setFont(new Font("Arial", Font.PLAIN, 16));
		citta.setFont(new Font("Arial", Font.PLAIN, 16));
		giorno.setFont(new Font("Arial", Font.PLAIN, 16));
		mese.setFont(new Font("Arial", Font.PLAIN, 16));
		anno.setFont(new Font("Arial", Font.PLAIN, 16));
		tecnico.setFont(new Font("Arial", Font.PLAIN, 16));
		committenteCap.setFont(new Font("Arial", Font.PLAIN, 16));
		committenteCitta.setFont(new Font("Arial", Font.PLAIN, 16));
		committenteCivico.setFont(new Font("Arial", Font.PLAIN, 16));
		committenteIntestatario.setFont(new Font("Arial", Font.PLAIN, 16));
		committenteVia.setFont(new Font("Arial", Font.PLAIN, 16));
		cell.setFont(new Font("Arial", Font.PLAIN, 16));
		mail.setFont(new Font("Arial", Font.PLAIN, 16));
		tel.setFont(new Font("Arial", Font.PLAIN, 16));
		provincia.setFont(new Font("Arial", Font.PLAIN, 16));
		committenteProvincia.setFont(new Font("Arial", Font.PLAIN, 16));

		giorno.setPreferredSize(new Dimension(50, 30));
		mese.setPreferredSize(new Dimension(50, 30));
		anno.setPreferredSize(new Dimension(70, 30));
		tecnico.setPreferredSize(new Dimension(300, 30));
		provincia.setPreferredSize(new Dimension(70, 30));
		committenteProvincia.setPreferredSize(new Dimension(70, 30));

		tipoEdificio.setOpaque(false);
		tipoEdificioAltro.setOpaque(false);
		intestatario.setOpaque(false);
		via.setOpaque(false);
		nCivico.setOpaque(false);
		cap.setOpaque(false);
		citta.setOpaque(false);
		giorno.setOpaque(false);
		mese.setOpaque(false);
		anno.setOpaque(false);
		tecnico.setOpaque(false);
		committenteCap.setOpaque(false);
		committenteCitta.setOpaque(false);
		committenteCivico.setOpaque(false);
		committenteIntestatario.setOpaque(false);
		committenteVia.setOpaque(false);
		cell.setOpaque(false);
		mail.setOpaque(false);
		tel.setOpaque(false);
		provincia.setOpaque(false);
		committenteProvincia.setOpaque(false);
	}

	public String print() {
		String print = "";

		if (modifyTipoEdificio)
			print = print + "#" + tipoEdificioAltro.getText();
		else
			print = print + "#" + tipoEdificio.getSelectedIndex();
		print = print + "\n#" + intestatario.getText();
		print = print + "\n#" + via.getText();
		print = print + "\n#" + nCivico.getText();
		print = print + "\n#" + citta.getText();
		print = print + "\n#" + cap.getText();
		print = print + "\n#" + provincia.getText();
		print = print + "\n#" + giorno.getText();
		print = print + "\n#" + mese.getText();
		print = print + "\n#" + anno.getText();
		print = print + "\n#" + tecnico.getText();

		print = print + "\n#" + committenteIntestatario.getText();
		print = print + "\n#" + committenteVia.getText();
		print = print + "\n#" + committenteCivico.getText();
		print = print + "\n#" + committenteCitta.getText();
		print = print + "\n#" + committenteCap.getText();
		print = print + "\n#" + committenteProvincia.getText();
		print = print + "\n#" + mail.getText();
		print = print + "\n#" + cell.getText();
		print = print + "\n#" + tel.getText();

		print = print + professionista.print();

		return print;

	}

	public void setElement(String data) {
		Scanner c = new Scanner(data);
		c.nextLine();

		String tmp = c.nextLine();
		try {
			tipoEdificio.setSelectedIndex(Integer.parseInt(tmp));
		} catch (NumberFormatException e) {
			tipoEdificioAltro.setText(tmp);
			row12.remove(tipoEdificio);
			row12.add(tipoEdificioAltro, "cell 0 0 3 1");
			modifyTipoEdificio = true;


		}
		intestatario.setText(c.nextLine());
		via.setText(c.nextLine());
		nCivico.setText(c.nextLine());
		citta.setText(c.nextLine());
		cap.setText(c.nextLine());
		provincia.setText(c.nextLine());
		giorno.setText(c.nextLine());
		mese.setText(c.nextLine());
		anno.setText(c.nextLine());

		tecnico.setText(c.nextLine());

		committenteIntestatario.setText(c.nextLine());
		committenteVia.setText(c.nextLine());
		committenteCivico.setText(c.nextLine());
		committenteCitta.setText(c.nextLine());
		committenteCap.setText(c.nextLine());
		committenteProvincia.setText(c.nextLine());
		mail.setText(c.nextLine());
		cell.setText(c.nextLine());
		try {
			tel.setText(c.nextLine());
		} catch (Exception e) {
			tel.setText("");
		}

		st.refresh();
	}

	public void setProfessionista(String data) {
		professionista.setElement(data);
	}

	public Document PDFfront(Document doc) {
		Paragraph dati;
		// titolo
		dati = new Paragraph("ARCHIMEDE GROUP", FontFactory.getFont(FontFactory.TIMES, 16));
		try {
			dati.setSpacingAfter(10);
			dati.setAlignment(Element.ALIGN_CENTER);
			doc.add(dati);
		} catch (DocumentException e) {
			e.printStackTrace();
		}

		// logo archimede
		try {
			Image logo = Image.getInstance(ClassLoader.getSystemResource("logo.jpg"));
			logo.setAbsolutePosition(doc.getPageSize().getWidth() / 2 - 80, 540);
			logo.scaleAbsolute(160, 160);
			doc.add(logo);

		} catch (BadElementException e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
		} catch (MalformedURLException e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
		} catch (IOException e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
		} catch (DocumentException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

		// numero rtd
		dati = new Paragraph("RTD " + (st.getCount() + 346), FontFactory.getFont(FontFactory.TIMES, 26));
		try {
			dati.setSpacingAfter(10);
			dati.setSpacingBefore(250);
			dati.setAlignment(Element.ALIGN_CENTER);
			doc.add(dati);
		} catch (DocumentException e) {
			e.printStackTrace();
		}

		// stack tra logo e dati dell'immobile
		dati = new Paragraph("_____________________________________", FontFactory.getFont(FontFactory.TIMES, 26, new BaseColor(0, 102, 255)));
		try {
			dati.setSpacingAfter(20);
			dati.setAlignment(Element.ALIGN_CENTER);
			doc.add(dati);
		} catch (DocumentException e) {
			e.printStackTrace();
		}

		// sottotitolo
		dati = new Paragraph("RELAZIONE TECNICA DIAGNOSTICA", FontFactory.getFont(FontFactory.TIMES, 20));
		dati.setAlignment(Element.ALIGN_CENTER);
		dati.setSpacingAfter(30);
		dati.setSpacingBefore(30);
		try {
			doc.add(dati);
		} catch (DocumentException e) {
			e.printStackTrace();
		}

		// tipo edificio
		if (modifyTipoEdificio)
			dati = new Paragraph(tipoEdificioAltro.getText(), FontFactory.getFont(FontFactory.TIMES, 18));
		else
			dati = new Paragraph((String) tipoEdificio.getSelectedItem(), FontFactory.getFont(FontFactory.TIMES, 18));
		dati.setAlignment(Element.ALIGN_CENTER);
		try {
			doc.add(dati);
		} catch (DocumentException e) {
			e.printStackTrace();
		}
		// intestatario
		dati = new Paragraph(intestatario.getText(), FontFactory.getFont(FontFactory.TIMES, 18));
		dati.setAlignment(Element.ALIGN_CENTER);
		try {
			doc.add(dati);
		} catch (DocumentException e) {
			e.printStackTrace();
		}
		// via + civico
		dati = new Paragraph("Via " + via.getText() + " , " + nCivico.getText(), FontFactory.getFont(FontFactory.TIMES, 18));
		dati.setAlignment(Element.ALIGN_CENTER);
		try {
			doc.add(dati);
		} catch (DocumentException e) {
			e.printStackTrace();
		}

		// cap, citta (provincia)
		dati = new Paragraph(cap.getText() + " , " + citta.getText() + " (" + provincia.getText() + ")", FontFactory.getFont(FontFactory.TIMES, 18));
		dati.setAlignment(Element.ALIGN_CENTER);
		try {
			doc.add(dati);
		} catch (DocumentException e) {
			e.printStackTrace();
		}
		return doc;
	}

	public Document PDFindice(Document doc) {
		Paragraph dati;
		String line = "";

		// tipo edificio
		if (modifyTipoEdificio)
			line = "Immobile    ...........................                       " + tipoEdificioAltro.getText();

		else
			line = "Immobile    ...........................                       " + (String) tipoEdificio.getSelectedItem();
		dati = new Paragraph(line, FontFactory.getFont(FontFactory.TIMES, 12));
		dati.setAlignment(Element.ALIGN_LEFT);
		try {
			dati.setSpacingBefore(50);
			doc.add(dati);
		} catch (DocumentException e) {
			e.printStackTrace();
		}

		// via + civico
		line = "                                                                     Via " + via.getText() + " , " + nCivico.getText();
		dati = new Paragraph(line, FontFactory.getFont(FontFactory.TIMES, 12));
		dati.setAlignment(Element.ALIGN_LEFT);
		try {
			doc.add(dati);
		} catch (DocumentException e) {
			e.printStackTrace();
		}
		// cap, citta' (provincia)
		line = "                                                                     " + cap.getText() + " , " + citta.getText() + " (" + provincia.getText()
				+ ")";
		dati = new Paragraph(line, FontFactory.getFont(FontFactory.TIMES, 12));
		dati.setAlignment(Element.ALIGN_LEFT);
		try {
			doc.add(dati);
		} catch (DocumentException e) {
			e.printStackTrace();
		}

		// committente
		line = "Committente    .....................                        " + committenteIntestatario.getText();
		dati = new Paragraph(line, FontFactory.getFont(FontFactory.TIMES, 12));
		dati.setAlignment(Element.ALIGN_LEFT);
		try {
			dati.setSpacingBefore(20);
			doc.add(dati);
		} catch (DocumentException e) {
			e.printStackTrace();
		}
		// via + civico committente
		line = "                                                                      Via " + committenteVia.getText() + " , " + committenteCivico.getText();
		dati = new Paragraph(line, FontFactory.getFont(FontFactory.TIMES, 12));
		dati.setAlignment(Element.ALIGN_LEFT);
		try {
			doc.add(dati);
		} catch (DocumentException e) {
			e.printStackTrace();
		}
		// cap, citta' (provincia) committente
		line = "                                                                      " + committenteCap.getText() + " , " + committenteCitta.getText()
				+ " (" + committenteProvincia.getText() + ")";
		dati = new Paragraph(line, FontFactory.getFont(FontFactory.TIMES, 12));
		dati.setAlignment(Element.ALIGN_LEFT);
		try {
			doc.add(dati);
		} catch (DocumentException e) {
			e.printStackTrace();
		}

		// mail committente
		line = "                                                                      Email: " + mail.getText();
		dati = new Paragraph(line, FontFactory.getFont(FontFactory.TIMES, 12));
		dati.setAlignment(Element.ALIGN_LEFT);
		try {
			doc.add(dati);
		} catch (DocumentException e) {
			e.printStackTrace();
		}
		// cellulare committente
		line = "                                                                      Cell. " + cell.getText();
		dati = new Paragraph(line, FontFactory.getFont(FontFactory.TIMES, 12));
		dati.setAlignment(Element.ALIGN_LEFT);
		try {
			doc.add(dati);
		} catch (DocumentException e) {
			e.printStackTrace();
		}
		// telefono committente
		line = "                                                                      Tel. " + tel.getText();
		dati = new Paragraph(line, FontFactory.getFont(FontFactory.TIMES, 12));
		dati.setAlignment(Element.ALIGN_LEFT);
		try {
			doc.add(dati);
		} catch (DocumentException e) {
			e.printStackTrace();
		}

		// se ci sono professionisti li aggiungo
		int numeroProfessionisti = professionista.pdf(doc);

		// indice
		dati = new Paragraph("SOMMARIO", FontFactory.getFont(FontFactory.TIMES, 13, Font.BOLD));
		dati.setAlignment(Element.ALIGN_LEFT);
		try {
			if (numeroProfessionisti == 0)
				dati.setSpacingBefore(80);
			else if (numeroProfessionisti == 1)
				dati.setSpacingBefore(60);
			if (numeroProfessionisti == 2)
				dati.setSpacingBefore(20);
			dati.setSpacingAfter(10);
			doc.add(dati);
		} catch (DocumentException e) {
			e.printStackTrace();
		}

		dati = new Paragraph("1.       Premesse ", FontFactory.getFont(FontFactory.TIMES, 12));
		dati.setAlignment(Element.ALIGN_LEFT);
		try {
			doc.add(dati);
		} catch (DocumentException e) {
			e.printStackTrace();
		}

		dati = new Paragraph("2.       Dati climatici ambientali", FontFactory.getFont(FontFactory.TIMES, 12));
		dati.setAlignment(Element.ALIGN_LEFT);
		try {
			doc.add(dati);
		} catch (DocumentException e) {
			e.printStackTrace();
		}
		dati = new Paragraph("3.       Dati dell'immobile ", FontFactory.getFont(FontFactory.TIMES, 12));
		dati.setAlignment(Element.ALIGN_LEFT);
		try {
			doc.add(dati);
		} catch (DocumentException e) {
			e.printStackTrace();
		}
		dati = new Paragraph("   3.1  Caratteristiche dei muri e delle pareti ", FontFactory.getFont(FontFactory.TIMES, 12));
		dati.setAlignment(Element.ALIGN_LEFT);
		try {
			doc.add(dati);
		} catch (DocumentException e) {
			e.printStackTrace();
		}
		dati = new Paragraph("   3.2  Impermeabilizzazioni ", FontFactory.getFont(FontFactory.TIMES, 12));
		dati.setAlignment(Element.ALIGN_LEFT);
		try {
			doc.add(dati);
		} catch (DocumentException e) {
			e.printStackTrace();
		}
		dati = new Paragraph("   3.3  Tipo dell'intonaco, della pittura e periodo ", FontFactory.getFont(FontFactory.TIMES, 12));
		dati.setAlignment(Element.ALIGN_LEFT);
		try {
			doc.add(dati);
		} catch (DocumentException e) {
			e.printStackTrace();
		}
		dati = new Paragraph("4.       Strumentazione utilizzata e condizioni ", FontFactory.getFont(FontFactory.TIMES, 12));
		dati.setAlignment(Element.ALIGN_LEFT);
		try {
			doc.add(dati);
		} catch (DocumentException e) {
			e.printStackTrace();
		}
		dati = new Paragraph("5.       Pianta dell'edificio con punti di rilievo ", FontFactory.getFont(FontFactory.TIMES, 12));
		dati.setAlignment(Element.ALIGN_LEFT);
		try {
			doc.add(dati);
		} catch (DocumentException e) {
			e.printStackTrace();
		}
		dati = new Paragraph("6.       Report termografico e rilievo umidita' con metodo ponderale Darr ", FontFactory.getFont(FontFactory.TIMES, 12));
		dati.setAlignment(Element.ALIGN_LEFT);
		try {
			doc.add(dati);
		} catch (DocumentException e) {
			e.printStackTrace();
		}
		dati = new Paragraph("7.       Analisi tipologia sali ", FontFactory.getFont(FontFactory.TIMES, 12));
		dati.setAlignment(Element.ALIGN_LEFT);
		try {
			doc.add(dati);
		} catch (DocumentException e) {
			e.printStackTrace();
		}
		dati = new Paragraph("8.       Potenziali elettrici ", FontFactory.getFont(FontFactory.TIMES, 12));
		dati.setAlignment(Element.ALIGN_LEFT);
		try {
			doc.add(dati);
		} catch (DocumentException e) {
			e.printStackTrace();
		}
		dati = new Paragraph("9.       Punti critici e soluzioni ", FontFactory.getFont(FontFactory.TIMES, 12));
		dati.setAlignment(Element.ALIGN_LEFT);
		try {
			doc.add(dati);
		} catch (DocumentException e) {
			e.printStackTrace();
		}
		return doc;
	}

	public Document PDFpremesse(Document doc) {
		// premesse
		Chunk underline = new Chunk("1. Premesse", FontFactory.getFont(FontFactory.TIMES, 16, Font.BOLD));
		underline.setUnderline(1.2f, -2f); // 0.1 thick, -2 y-location

		try {
			doc.add(underline);
		} catch (DocumentException e2) {
			// TODO Auto-generated catch block
			e2.printStackTrace();
		}

		// data analisi
		Paragraph dati;
		dati = new Paragraph("Data analisi diagnostica : " + giorno.getText() + "/" + mese.getText() + "/" + anno.getText(), FontFactory.getFont(
				FontFactory.TIMES, 12));

		try {
			doc.add(dati);
		} catch (DocumentException e2) {
			// TODO Auto-generated catch block
			e2.printStackTrace();
		}

		// tecnico esecutore
		dati = new Paragraph("Tecnico esecutore delle misurazioni : " + tecnico.getText(), FontFactory.getFont(FontFactory.TIMES, 12));
		try {
			dati.setSpacingAfter(10);
			doc.add(dati);
		} catch (DocumentException e2) {
			// TODO Auto-generated catch block
			e2.printStackTrace();
		}
		return doc;
	}
}
